<?php
class pengiriman extends CI_Model {

	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function insert($data){
        $this->db->insert('pengiriman',$data);
    }

    function update($id,$data){
	$id_pengiriman="'".$id."'";
	
        $this->db->where('no_pengiriman', $id_pengiriman);
        $this->db->update('pengiriman', $data);
    }
	
	function updatePesanan($id,$data){
	$id_pesanan=''.$id.'';
	
        $this->db->where('nomer_pesanan', $id_pesanan);
        $this->db->update('pesanan', $data);
    }

    function delete($data){
        $this->db->where('id_pengiriman', $data);
        $this->db->delete('pengiriman');
    }

    function get_by_id($id){
        $this->db->from('pengiriman');
        $query = $this->db->get();
        return $query->result_array();
    }
	 function get_all(){
        $this->db->from('pengiriman');
		
        $query = $this->db->get();
        return $query->result_array();
    }

    function get_allFilter(){
        $this->db->from('pengiriman');
		$this->db->where('status',1);
        $query = $this->db->get();
        return $query->result_array();
    }
	
	function get_pesanan(){
        $this->db->select('*');
        $this->db->from('pesanan');
        $this->db->where('status_pesanan',0);
         $query = $this->db->get();
        return $query->result_array();
    }
	
	function get_karyawan(){
        $this->db->select('*');
        $this->db->from('karyawan');
       // $this->db->where('status_pesanan',0);
         $query = $this->db->get();
        return $query->result_array();
    }
	
    function get_list(){
	 
        $this->db->select('*,pengiriman.status as status_pengiriman,pengiriman.tanggal as tanggal_pengiriman,konsumen.nama as nama_konsumen,konsumen.alamat as alamat_konsumen, karyawan.nama as nama_karyawan, barang.nama as nama_barang');
        $this->db->from('pengiriman,pesanan,konsumen,karyawan,barang');
	    $this->db->where('pengiriman.nomer_pesanan`=`pesanan.nomer_pesanan');
		$this->db->where('pengiriman.karyawan`=`karyawan.id_karyawan');
		$this->db->where('pesanan.no_konsumen`=`konsumen.id_konsumen');
		$this->db->where('pesanan.id_barang`=`barang.id_barang');
        $query = $this->db->get();
        return $query->result_array();
    }
	
	//get maks pengiriman
	
	function maks_pengiriman(){
        $query =$this->db->query('select max(id_pengiriman) as maksid from pengiriman');
     
        return $query ;
       
    }

    function get_by_nama($nama){
        $this->db->select('id_pengiriman');
        $this->db->from('pengiriman');
        $this->db->where('nama',$nama);
        $query = $this->db->get();
        return $query;
    }

   
}